using JGSY.CMS.LowCode.Platform.Domain.Entities;

namespace JGSY.CMS.LowCode.Platform.Infrastructure.Services
{
    /// <summary>
    /// 增强审计服务接口
    /// 提供业务操作审计、数据变更跟踪、性能监控等高级审计功能
    /// </summary>
    public interface IEnhancedAuditService
    {
        /// <summary>
        /// 记录权限拒绝访问审计日志
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <param name="permissionCode">权限代码</param>
        /// <param name="requestPath">请求路径</param>
        /// <param name="httpMethod">HTTP方法</param>
        /// <param name="reason">拒绝原因</param>
        /// <param name="tenantId">租户ID</param>
        /// <param name="correlationId">关联ID</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>审计日志实体</returns>
        Task<AuditLog> LogPermissionDeniedAsync(
            string userId,
            string permissionCode,
            string requestPath,
            string httpMethod,
            string reason,
            string? tenantId = null,
            string? correlationId = null,
            CancellationToken cancellationToken = default);

        /// <summary>
        /// 记录业务操作审计日志
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <param name="operationType">操作类型</param>
        /// <param name="operationName">操作名称</param>
        /// <param name="targetType">目标类型</param>
        /// <param name="targetId">目标ID</param>
        /// <param name="operationData">操作数据</param>
        /// <param name="tenantId">租户ID</param>
        /// <param name="correlationId">关联ID</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>审计日志实体</returns>
        Task<AuditLog> LogBusinessOperationAsync(
            string userId,
            string operationType,
            string operationName,
            string targetType,
            string targetId,
            Dictionary<string, object>? operationData = null,
            string? tenantId = null,
            string? correlationId = null,
            CancellationToken cancellationToken = default);

        /// <summary>
        /// 记录数据变更审计日志
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <param name="entityType">实体类型</param>
        /// <param name="entityId">实体ID</param>
        /// <param name="changeType">变更类型</param>
        /// <param name="oldValues">旧值</param>
        /// <param name="newValues">新值</param>
        /// <param name="tenantId">租户ID</param>
        /// <param name="correlationId">关联ID</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>审计日志实体</returns>
        Task<AuditLog> LogDataChangeAsync(
            string userId,
            string entityType,
            string entityId,
            string changeType,
            Dictionary<string, object>? oldValues = null,
            Dictionary<string, object>? newValues = null,
            string? tenantId = null,
            string? correlationId = null,
            CancellationToken cancellationToken = default);

        /// <summary>
        /// 记录性能监控审计日志
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <param name="operationName">操作名称</param>
        /// <param name="duration">执行时长（毫秒）</param>
        /// <param name="performanceMetrics">性能指标</param>
        /// <param name="tenantId">租户ID</param>
        /// <param name="correlationId">关联ID</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>审计日志实体</returns>
        Task<AuditLog> LogPerformanceAsync(
            string userId,
            string operationName,
            long duration,
            Dictionary<string, object>? performanceMetrics = null,
            string? tenantId = null,
            string? correlationId = null,
            CancellationToken cancellationToken = default);

        /// <summary>
        /// 记录系统事件审计日志
        /// </summary>
        /// <param name="eventType">事件类型</param>
        /// <param name="eventName">事件名称</param>
        /// <param name="eventData">事件数据</param>
        /// <param name="userId">用户ID</param>
        /// <param name="tenantId">租户ID</param>
        /// <param name="correlationId">关联ID</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>审计日志实体</returns>
        Task<AuditLog> LogSystemEventAsync(
            string eventType,
            string eventName,
            Dictionary<string, object>? eventData = null,
            string? userId = null,
            string? tenantId = null,
            string? correlationId = null,
            CancellationToken cancellationToken = default);

        /// <summary>
        /// 批量记录审计日志
        /// </summary>
        /// <param name="auditLogs">审计日志列表</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>记录的审计日志数量</returns>
        Task<int> LogBatchAsync(
            IEnumerable<AuditLog> auditLogs,
            CancellationToken cancellationToken = default);
    }
}
